<html>
    <head>
        <meta charset="utf-8">
        <title>五个很实用的Django 项目推荐</title>
        <link rel="stylesheet" href="../assets/stylesheets/global.css">
        <link rel="stylesheet" href="../assets/stylesheets/words.css">
        <link rel="stylesheet" href="../assets/stylesheets/monokai.css">
        <link rel="stylesheet" href="../assets/stylesheets/table.css">
        <link rel="shortcut icon" href="../assets/images/favicon.ico" type="image/x-icon">
        <link rel="icon" href="../assets/images/favicon.ico" type="image/x-icon">
        <script>
            // 统计代码
            (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
                m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
                })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

            ga('create', 'UA-93231524-1', 'auto');
            ga('send', 'pageview');
        </script>
    </head>
    <body>
        <div id="header">
            <a href="../index.html"><div id="logo">JG</div></a>
        </div>
        <div id="container" class="typo">
            <div id="article">
                <h1>五个很实用的Django 项目推荐</h1>
                <h4>Posted August 16, 2016</h4>

                <p>很多Django的包都能很大的增加我们的开发效率或者增加我们项目的功能， 比如: <a href="https://github.com/tomchristie/django-rest-framework/">django-rest-framework</a> 、<a href="https://github.com/torchbox/wagtail">wagtail</a>, 它们带来了很棒的功能. 但是今天我想推荐一些其他的包， 更有爱的包.</p>

<h2><a href="https://github.com/groveco/django-sql-explorer">django-sql-explorer</a></h2>

<p>有时候你的用户想通过执行SQL的方式来访问你数据库里面的数据， 但处于某些安全的原因，你不能给他们直接执行数据库的权限.但django-sql-explorer 可以让用户通过web端沙盒的方式执行SQL并可以下载执行结果(CSV), 排序数据和数据透视操作.</p>

<p><p class="hassubimage"><img src="/uploads/images/django-sql-explorer-1.png" alt="A view of a query"></p>
                    <p class="img-title">A view of a query</p>

                    <p class="hassubimage"><img src="/uploads/images/django-sql-explorer-2.png" alt="Quick access to DB schema info"></p>
                    <p class="img-title">Quick access to DB schema info</p>

                    <p class="hassubimage"><img src="/uploads/images/django-sql-explorer-3.png" alt="Viewing all queries"></p>
                    <p class="img-title">Viewing all queries</p></p>

<h2><a href="https://github.com/bradleyayers/django-tables2">django-tables-2</a></h2>

<p>很多数据在web中通过表格展示， 通过它能够很方便的操作HTML表格, 让你非常容易的在Django中操作表格. 它提供了<code>数据排列</code>、<code>数据排序</code>、<code>数据分页</code>.</p>

<p>可以通过<a href="https://github.com/carltongibson/django-filter">django-filter</a>很容易的扩展搜索和过滤数据, 无论前端是bootstrap还是foundation或你自己开发的前端, 它可以完全兼容.</p>

        
<div class="highlight"><pre>:::python
import django_tables2 as tables
from .models import Address
class AddressTable(tables.Table):
    user = tables.Column(accessor='address.user')
    zip_code = tables.Column(verbose_name='Zip')
    city = tables.Column(verbose_name='Town')

    class Meta:
        model = Address
        order_by = '-zip_code'
        fields = sequence = ('user', 'zip_code', 'city',)</pre></div>

<h2><a href="https://github.com/django-wiki/django-wiki">django-wiki</a></h2>

<p>有时, 你需要wiki功能, 可以使用django-wiki来扩展到自己的项目中.它也可以工作在某一个区域, 当然这需要你自己在模版中指定. 它支持markdown, 版本控制, 和开箱即用的Box UI.</p>

<p><p class="hassubimage"><img src="/uploads/images/django-wiki-demo.png" alt="django-wiki"></p>
                    <p class="img-title">django-wiki</p></p>

<h2><a href="https://github.com/jedie/django-reversion-compare">django-reversion-compare</a></h2>

<p><a href="https://github.com/etianen/django-reversion">django-reversion</a> 已经非常棒了, 然而对每一个变更都加入了比较功能, 你可以对变更做如下图一样直观的比较.</p>

<p><p class="hassubimage"><img src="/uploads/images/django-reversion-compare.png" alt="django-reversion-compare"></p>
</p>

<h2><a href="https://github.com/zapier/django-rest-hooks">django-rest-hooks</a></h2>

<p>REST APIs 是很棒的接口设计, 而且<a href="https://github.com/tomchristie/django-rest-framework/">django-rest-framework</a>能很好的提供这个功能. 但是如果你仅仅是基于事件来获取数据, 那么你需要一个webhook. 使用这个包可以非常容易的以REST框架装饰你的模型. 下面就是相应的代码.</p>

        
<div class="highlight"><pre>:::python
### settings.py ###

INSTALLED_APPS = (
    # other apps here...
    'rest_hooks',
)

HOOK_EVENTS = {
    'book.added':       'bookstore.Book.created',
    'book.changed':     'bookstore.Book.updated+',
    'book.removed':     'bookstore.Book.deleted',
    'book.read':        'bookstore.Book.read',
    'user.logged_in':    None
}

### bookstore/models.py ###

class Book(models.Model):
    user = models.ForeignKey('auth.User')
    title = models.CharField(max_length=128)
    pages = models.PositiveIntegerField()
    fiction = models.BooleanField()

    def serialize_hook(self, hook):
        return {
            'hook': hook.dict(),
            'data': {
                'id': self.id,
                'title': self.title,
                'pages': self.pages,
                'fiction': self.fiction,
            }
        }

    def mark_as_read(self):
        from rest_hooks.signals import hook_event
        hook_event.send(
            sender=self.__class__,
            action='read',
            instance=self # the Book object
        )
### USAGE ###
>>> from django.contrib.auth.models import User
>>> from rest_hooks.model import Hook
>>> jrrtolkien = User.objects.create(username='jrrtolkien')
>>> hook = Hook(user=jrrtolkien,
                event='book.added',
                target='http://example.com/target.php')
>>> hook.save()     # creates the hook and stores it for later...
>>> from bookstore.models import Book
>>> book = Book(user=jrrtolkien,
                title='The Two Towers',
                pages=327,
                fiction=True)
>>> book.save()     # fires off 'bookstore.Book.created' hook automatically
...</pre></div>

<h4>原文地址: https://medium.com/@raiderrobert/5-django-packages-that-get-too-little-love-d55232c28640</h4>

            </div>
            <div id="footer">
                <a href="../words.html"><div id="more-words">MORE WORDS</div></a>
            </div>
        </div>
    </body>
</html>